# -*- coding:utf-8 -*-

'''多线程学习'''

import threading

#在线程中调用的方法
def run_in_thread():
	print 'Thread %s is running' % threading.current_thread().name
	
#主线程中调用
print 'thread %s is running' % threading.current_thread().name
# 名字仅仅在打印时用来显示，完全没有其他意义，如果不起名字Python就自动给线程命名为Thread-1，Thread-2……
t=threading.Thread(target=run_in_thread,name='ChildThread')
t.start()
t.join()
print 'thread %s is end' % threading.current_thread().name


#创建锁
# lock=threading.Lock()
#获取锁
# lock.acquire()


'''ThreadLocal'''

#创建threadlocal

local_school=threading.local()

def thread_fuc(firstname):
	#绑定ThreadLocal的name
	local_school.student=firstname
	printName()
	
def printName():
	print 'local_school.student=%s in(thread[%s])' % (local_school.student,threading.current_thread().name)
	
t1=threading.Thread(target=thread_fuc,args=('Tom',))
t2=threading.Thread(target=thread_fuc,args=('Jerry',))
t1.start()
t2.start()
	
